package rubbish;

import java.util.Set;
import java.util.Spliterator;

import map.Map1;
import rubbish.TreeMap1.AscendingSubMap.AscendingEntrySetView;
import rubbish.TreeMap1.NavigableSubMap.SubMapEntryIterator;

public class TestTreeMap1 {

    @SuppressWarnings({ "unchecked", "rawtypes", "unused" })
	public static void testInsert() throws Exception {
    	System.out.println("computeRedLevel:"+TreeMap1.computeRedLevel(12));
    	TreeMap1<Integer, Integer> mapr = new TreeMap1<Integer, Integer>();
    	mapr.put(10, 10);
    	mapr.put(12, 12);
    	
        TreeMap1<Integer, Integer> map = new TreeMap1<Integer, Integer>();
        map.put(0, 0);
        Set<Map1.Entry<Integer, Integer>> ss2 = map.entrySet();
        map.put(1, 1);//Eclipse移到map上面去显示的是map的toString()方法或者父类的toString()方法。
        Set<Map1.Entry<Integer, Integer>> ss1 = map.entrySet();
        System.out.println(map.toString());//toString是AbstractMap1的方法
        map.put(2, 2);
        map.put(3, 3);
        map.put(4, 4);
        map.put(5, 5);
        map.put(6, 6);
        map.put(7, 7);
        map.put(8, 8);
        map.put(9, 9);
        map.put(10, 10);
        Set<Map1.Entry<Integer, Integer>> ss = map.entrySet();
//      Collection c = (Collection) map.values();
        
        TreeMap1<Integer, Integer> map1 = new TreeMap1<Integer, Integer>(map);
        map1.putAll(map);
        System.out.println(map1.toString());//5-BLACK-5  2-BLACK-2  8-BLACK-8  0-BLACK-0  3-BLACK-3  6-BLACK-6  9-BLACK-9  1-RED-1  4-RED-4  7-RED-7  10-RED-10  

        Spliterator s2 = map1.keySet().spliterator();//前面分割出去，留下来后面的。
        Spliterator s21 = s2.trySplit();//分割出去的21：开始0结束root，side=-1，est=5。留下来的s2:开始root结束null，side=1，est=5
        Spliterator s22 = s21.trySplit();//出去的再分割，出去前面的（0---root.left）,留下来的（root.left----root）
        Spliterator s23 = s2.trySplit();//留下来的再分割， 
        
        Spliterator s1 = map1.entrySet().spliterator();
        Spliterator s11 = s1.trySplit();
        
        Spliterator s3 = map1.values().spliterator();
        
        AscendingEntrySetView sm = (AscendingEntrySetView) map1.subMap(3, 6).entrySet();//[[键=3,值=3,色=黑], [键=4,值=4,色=红], [键=5,值=5,色=黑]]
        int i = sm.size();
        SubMapEntryIterator sit = (SubMapEntryIterator) sm.iterator();
        while(sit.hasNext()) {
        	System.out.println(sit.next());
        }
        
    }


    public static void main(String[] args) throws Exception {
        testInsert();
    }
}

